//回复模板 tpl
import ejs from 'ejs'
const tpl = `
    <xml>
        <ToUserName><![CDATA[<%= toUserName %>]]></ToUserName>
        <FromUserName><![CDATA[<%= fromUserName %>]]></FromUserName>
        <CreateTime><%= createTime %></CreateTime>
        <MsgType><![CDATA[<%= msgType %>]]></MsgType>
        <% if (msgType === 'text'){ %>
            <Content><![CDATA[<%- content %>]]></Content>
        <% } else if (msgType === 'image'){ %>
        <Image>
            <MediaId><![CDATA[<%= content.mediaId %>]]></MediaId>
        </Image>
        <% } else if (msgType === 'voice'){ %>
        <Voice>
            <MediaId><![CDATA[<%= content.mediaId %>]]></MediaId>
        </Voice>
        <% } else if (msgType === 'video'){ %>
        <Video>
            <MediaId><![CDATA[<%= content.mediaId %>]]></MediaId>
            <Title><![CDATA[<%= content.title %>]]></Title>
            <Description><![CDATA[<%= content.description %>]]></Description>
        </Video>
        <% } else if (msgType === 'music'){ %>
        <Music>
            <Title><![CDATA[<%= content.title %>]]></Title>
            <Description><![CDATA[<%= content.description %>]]></Description>
            <MusicUrl><![CDATA[<%= content.musicUrl %>]]></MusicUrl>
            <HQMusicUrl><![CDATA[<%= content.hqMusicUrl %>]]></HQMusicUrl>
            <ThumbMediaId><![CDATA[<%= content.thumbMeiaId %>]]></ThumbMediaId>
        </Music>
        <% } else if (msgType === 'news'){ %>
        <ArticleCount><%= content.length %></ArticleCount>
        <Articles>
            <% content.forEach(function(item){ %>
                <item>
                <Title><![CDATA[<%= item.title %>]]></Title>
                <Description><![CDATA[<%= item.description %>]]></Description>
                <PicUrl><![CDATA[<%= item.picurl %>]]></PicUrl>
                <Url><![CDATA[<%= item.url %>]]></Url>
            </item>
        <% })%>
        </Articles>
        <% } %>
    </xml>
`

const complied = ejs.compile(tpl)
export default complied

/*回复文本消息
<xml>
    <ToUserName>< ![CDATA[toUser] ]></ToUserName>
    <FromUserName>< ![CDATA[fromUser] ]></FromUserName>
    <CreateTime>12345678</CreateTime>
    <MsgType>< ![CDATA[text] ]></MsgType>
    <Content>< ![CDATA[你好] ]></Content>
</xml>
*/

/* 回复图片消息
<xml>
    <ToUserName>< ![CDATA[toUser] ]></ToUserName>
    <FromUserName>< ![CDATA[fromUser] ]></FromUserName>
    <CreateTime>12345678</CreateTime>
    <MsgType>< ![CDATA[image] ]></MsgType>
    <Image>
        <MediaId>< ![CDATA[media_id] ]></MediaId>
    </Image>
</xml>
*/

/*回复语音消息
<xml>
    <ToUserName>< ![CDATA[toUser] ]></ToUserName>
    <FromUserName>< ![CDATA[fromUser] ]></FromUserName>
    <CreateTime>12345678</CreateTime>
    <MsgType>< ![CDATA[voice] ]></MsgType>
    <Voice>
        <MediaId>< ![CDATA[media_id] ]></MediaId>
    </Voice>
</xml>
 */

/* 回复视频消息
<xml>
    <ToUserName>< ![CDATA[toUser] ]></ToUserName>
    <FromUserName>< ![CDATA[fromUser] ]></FromUserName>
    <CreateTime>12345678</CreateTime>
    <MsgType>< ![CDATA[video] ]></MsgType>
    <Video>
        <MediaId>< ![CDATA[media_id] ]></MediaId>
        <Title>< ![CDATA[title] ]></Title>
        <Description>< ![CDATA[description] ]></Description>
    </Video>
</xml>
*/


/* 回复音乐消息
<xml>
    <ToUserName>< ![CDATA[toUser] ]></ToUserName>
    <FromUserName>< ![CDATA[fromUser] ]></FromUserName>
    <CreateTime>12345678</CreateTime>
    <MsgType>< ![CDATA[music] ]></MsgType>
    <Music>
        <Title>< ![CDATA[TITLE] ]></Title>
        <Description>< ![CDATA[DESCRIPTION] ]></Description>
        <MusicUrl>< ![CDATA[MUSIC_Url] ]></MusicUrl>
        <HQMusicUrl>< ![CDATA[HQ_MUSIC_Url] ]></HQMusicUrl>
        <ThumbMediaId>< ![CDATA[media_id] ]></ThumbMediaId>
    </Music>
</xml>
*/

/*回复图文消息 
<xml>
    <ToUserName>< ![CDATA[toUser] ]></ToUserName>
    <FromUserName>< ![CDATA[fromUser] ]></FromUserName>
    <CreateTime>12345678</CreateTime>
    <MsgType>< ![CDATA[news] ]></MsgType>
    <ArticleCount>1</ArticleCount>
    <Articles>
        <item>
            <Title>< ![CDATA[title1] ]></Title>
            <Description>< ![CDATA[description1] ]></Description>
            <PicUrl>< ![CDATA[picurl] ]></PicUrl>
            <Url>< ![CDATA[url] ]></Url>
        </item>
    </Articles>
</xml>
*/

